<template>
	<view class="systemSet" style="margin-top: 50px;">
			<view @tap='checkchoose'  v-if="identity == '1'" style="width:100%;height:200px;text-align: center;">
				<image :src="datas.image_head"  style="width:150px;height:150px"></image>
			</view>
			<view @tap='checkchoose' v-if="identity == '2'"  style="width:100%;height:200px;text-align: center;">
				<image :src="datas.store_img" style="width:150px;height:150px"></image>
			</view>
			
	</view>
	
</template>

<script>
	// #ifdef APP-PLUS
	const jyJPush = uni.requireNativePlugin('JY-JPush');
	let device = uni.getSystemInfoSync().platform;
	import AddressPicker from "@/components/address-picker/AddressPicker.vue"
	// #endif
	let timer = null;
	export default {
		
		data() {
			return {
				identity:uni.getStorageSync('identify')?uni.getStorageSync('identify'):'1',
				datas:{},
				domain:getApp().globalData.imgDomain,
				showPermission:false,
				image:'',

			};
		},
		onLoad(){
			
 		},
		onShow(){
			this.initData();
		},
		onShareAppMessage() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		onShareTimeline() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		methods:{
			
			initData(){
				this.tool.getUserInfo().then(res=>{
					console.log('用户信息',res);
					if(res){ 
						this.datas = res;
						
					}
				}).catch(err=>{
					console.log(err);
				})
				
			},
			checkchoose(){
				// #ifdef APP-PLUS
				if(!uni.getStorageSync('is_upload')){
					uni.showModal({
						title:'权限申请说明',
						content:'本次申请使用您的相机和存储权限用于更换应用内头像信息，是否同意',
						success:(op)=>{
							if(op.confirm){
								this.changeTx()
							}
						},
					})
				}else{
					this.changeTx()
				}
				// #endif
				
				// #ifdef MP-WEIXIN
				this.changeTx()
				// #endif
			},
			initStaff(){
				this.tool.getStaffInfo().then(res=>{
					// console.log(res);
					if(res){
						this.datas = res;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 设置头像
			changeTx(){
				// #ifdef MP-WEIXIN
				uni.chooseMedia({
					count:1,
					mediaType:['image'],
					sourceType:['album', 'camera'],
					sizeType:['original', 'compressed'],
					success:(info)=>{
						console.log(info);
						if(info.tempFiles.length){
							this.tool.upImg(info.tempFiles[0].tempFilePath).then(res=>{
								if(res){
									if(this.identity == '1'){
										this.tool.getData('User/changeInfo',{
											memberId:uni.getStorageSync('userId'),
											// image_head:getApp().globalData.imgDomain + res.image_path,
											image_head:res.image_path,
										}).then(res=>{
											if(res){
												this.initData();
											}
										}).catch(err=>{
											console.log(err);
										})
									}else{
										this.tool.getData('User/changeInfo',{
											storeId:uni.getStorageSync('storeId'),
											// store_img:getApp().globalData.imgDomain + res.image_path,
											store_img:res.image_path,
										}).then(res=>{
											if(res){
												this.initStaff();
											}
										}).catch(err=>{
											console.log(err);
										})
									}
								}
							}).catch(err=>{
								console.log(err);
							})
						}
					},
					fail:(err)=>{
						console.log(err);
					}
				})
				// #endif
				// #ifdef APP-PLUS
				uni.chooseImage({
					count:1,
					sourceType:['album', 'camera'],
					sizeType:['original', 'compressed'],
					success:(info)=>{
						uni.setStorageSync('is_upload',1);
						if(info.tempFiles.length){
							this.tool.upImg(info.tempFiles[0].path).then(res=>{
								console.log(res);
								if(res){
									if(this.identity == '1'){
										this.tool.getData('User/changeInfo',{
											memberId:uni.getStorageSync('userId'),
											// image_head:getApp().globalData.imgDomain + res.image_path,
											image_head:res.image_path,
										}).then(res=>{
											if(res){
												this.tool.getUserInfo().then(res=>{
													console.log('用户信息',res);
													if(res){ 
														this.datas = res;
														
													}
												}).catch(err=>{
													console.log(err);
												})
											}
										}).catch(err=>{
											console.log(err);
										})
									}else{
										this.tool.getData('User/changeInfo',{
											storeId:uni.getStorageSync('storeId'),
											// store_img:getApp().globalData.imgDomain + res.image_path,
											store_img:res.image_path,
										}).then(res=>{
											if(res){
												this.initStaff();
											}
										}).catch(err=>{
											console.log(err);
										})
									}
								}
							}).catch(err=>{
								console.log(err);
							})
						}
					},
					fail:(err)=>{
						console.log(err);
					}
				})

				// #endif
			},
		}
	}
	
</script>

<style lang="scss">
	page{
		background: white;
	}
	.systemSet{
		width: 100%;
		padding: 0 4%;
		box-sizing: border-box;
	}
</style>
